package com.example.demo.listener;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class MsgListener {

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "notice.queue", durable = "true"),
                    exchange = @Exchange(name = "pay.top", type = "topic"),
                    key = "notice.*"
            )
    })
    public void listenSimpleQueue(String msg) {
        log.info("已收到通知: {}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "notice.phone.queue", durable = "true"),
                    exchange = @Exchange(name = "pay.top", type = "topic"),
                    key = "notice.phone"
            )
    })
    public void listenNoticePhoneQueue(String msg) {
        log.info("已收到手机通知: {}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "notice.email.queue", durable = "true"),
                    exchange = @Exchange(name = "pay.top", type = "topic"),
                    key = "notice.email"
            )
    })
    public void listenNoticeEmailQueue(String msg) {
        log.info("已收到邮箱通知: {}", msg);
    }


    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "notice.web.queue", durable = "true"),
                    exchange = @Exchange(name = "pay.top", type = "topic"),
                    key = "notice.web"
            )
    })
    public void listenNoticeWebQueue(String msg) {
        log.info("已收到站内消息: {}", msg);
    }
}
